/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

/**
 * <p>Project: jse2303 - VvolatileDemo</p>
 * <p>Powered by webrx On 2023-07-27 09:31:16</p>
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class VvolatileDemo {

    volatile boolean running = true;

    public static void main(String[] args) {
        var v = new VvolatileDemo();
        //T 线程
        var t = new Thread(v::m, "T");
        t.start();

        try {
            Thread.sleep(100);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //main 线程
        v.running = false;
        System.out.println("aaaa");
        System.out.println(v.running);
    }

    void m() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "线程开始");
        while (running) {

        }
        System.out.println(t + "线程结束");
    }
}
